package com.base.imgs.glide.transformation;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.support.annotation.NonNull;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;

import jp.wasabeef.glide.transformations.BitmapTransformation;

/**
 * 遮照层涂层，目前写死，之后可以修改构造器
 * Created by zhouzechao on 2018/1/5.
 */

public class ForgroundColorTransformation extends BitmapTransformation {

    private final int radius;

    public ForgroundColorTransformation(int radius) {
        this.radius = radius;
    }

    @Override
    public String key() {
        return "ReflectedTransformation()";
    }

    @Override
    protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
        int size = Math.max(outWidth, outHeight);

        Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, size, size);
        bitmap.setHasAlpha(true);
        Bitmap bitmapWithReflection = Bitmap.createBitmap(size,
                size, Bitmap.Config.ARGB_8888);

        Canvas canvas1 = new Canvas(bitmapWithReflection);
        canvas1.drawBitmap(bitmap, 0, 0, null);

        // 图片遮照层
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setAlpha(25);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            canvas1.drawRoundRect(0, 0, size, size, radius, radius, paint);
        }

        return bitmapWithReflection;
    }
}
